 var table ,form ,laypage ,layer ,element ,laydate ,upload//时间组件
$(function(){
	 layui.use(['table','form','laypage','layer', 'element', 'laydate','upload'], function(){
          table = layui.table;
          form=layui.form;
          laypage = layui.laypage ;//分页
          layer = layui.layer ;//弹层
          element = layui.element; //元素操作
          laydate = layui.laydate; //时间组件 
          upload = layui.upload;
          var groupId = getQueryString("groupId");
          $("#groupId").val(groupId);
          //表单验证
         form.verify({ 
        	 dictIdFile:function(value, item){
    			if(validate.isBlank(value))
    			{
    				return "请输入字典id";
    			}
      			if(!validate.isLength(value,1,50))
    		    {
    		      return '字典ID长度不能超过50个字符';
    		    }
    		    
    	    },
            dictNameFile: function(value, item){     		  
            	if(validate.isBlank(value))
    			{
    				return "请输入字典名称";
    			}
      			if(!validate.isLength(value,1,50))
    		    {
    		      return '字典名称长度不能超过50个字符';
    		    }
    		    
        	  },
        	 sortFile: function(value, item){    		  
        		if(validate.isBlank(value))
     			{
     				return "请输入排序号码";
     			}
        		if(!validate.isInteger(value))
        		{
        			return '排序只能输入整数';
        		}
        		if(!validate.intLimit8(value))
     			{
     				return '排序号码长度不能超过8位';
     			}
  	  	    },
  	  	     groupIdFile: function(value, item){     		  
	  	  	    if(validate.isBlank(value))
	  			{
	  				return "请输入组ID";
	  			}
	    		if(!validate.isLength(value,1,50))
	  		    {
	  		      return '组ID长度不能超过50个字符';
	  		    }
    	    }
    	    
       });    
  	  //表单提交事件
      form.on('submit(formDemo)', function(data){
    	    this.blur();//防止点回车，按钮重复点击
    	  	var loadIndex = layer.load(1);//显示加载层
    	  	//var requestData = formToJsonObj("form_edit", []);
    	  	var requestData = data.field;
    	  	console.log(requestData);
    	  	$.ajax({
	           url: "/sysDict/save.do",               //请求地址
	           type: "POST",              //请求类型
	           data:formatParam(requestData),              //请求数据
	           timeout: 200000,                //请求超时时间(毫秒)
	           headers: setHeader(),
	           success:function(res){         //请求成功
	        	   if(res.status == 200)
	  				{
	    				layer.msg(res.resultMsg, {icon: res.icon},function(){
	    					self.location=document.referrer
	    					//window.location.href = "/res/page/dictionary/positionType_list.html?permissionId="+permissionId
						}); 					
	  				}else if(res.status == 666){
	  					 TIMEOUT(); 
	  		        }else{
	  					layer.msg(res.resultMsg, {icon: res.icon});
	  				} 
	        	   layer.close(loadIndex);//关闭加载层 
              }
           })
    		return false; //阻止表单跳转。
    	});
    });
})


